package cn.kgc.ubagnet.controller;

import cn.kgc.ubagnet.pojo.Address;
import cn.kgc.ubagnet.service.address.AddressService;
import cn.kgc.ubagnet.service.buyer.BuyerService;
import cn.kgc.ubagnet.service.buyer.CrowdBuyerDetailService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AddressController {
    @Resource
    AddressService addressService;
    @Resource
    BuyerService ouyerService;

    @GetMapping("/address/list")
    @ResponseBody
    public List<Address> addresses(HttpSession session){

        //获取用户id
        Integer userid=ouyerService.seleByPhone(CrowdBuyerDetailService.phone).getUserid();
        List<Address> addresses = addressService.AddressList(userid);

        return addresses;
    }

    @GetMapping("/address/by/id")
    @ResponseBody
    public Address addressById(Integer id){
        Address address = addressService.AddressById(id);
        return address;
    }
}
